home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / Tools / freeWAIS-sf-1.1 / ir / wutil.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-05  |  47.7 KB  |  1,914 lines

  1. /* WIDE AREA INFORMATION SERVER SOFTWARE:
  2.    No guarantees or restrictions.  See the readme file for the full standard
  3.    disclaimer.
  4. */
  5.  
  6. /* Copyright (c) CNIDR (see ../COPYRIGHT) */
  7.  
  8.  
  9. /*--------------------------------------------------------------------------
  10.  * ABSTRACT:    WAIS_TOOLS
  11.  *
  12.  * AUTHOR
  13.  *   M. Tracy Shen
  14.  *
  15.  *
  16.  *------------------------------------------------------------------------*/
  17.  
  18. #ifndef lint
  19. static char *RCSid = "$Header: /usr/local/ls6/src+data/src/freeWAIS-sf/ir/RCS/wutil.c,v 1.4 1994/10/06 13:28:31 pfeifer Exp $";
  20. #endif
  21.  
  22. /* Change log:
  23.  * $Log: wutil.c,v $
  24.  * Revision 1.4  1994/10/06  13:28:31  pfeifer
  25.  * Patch from Mariusz Niewczas
  26.  *
  27.  * Revision 1.3  1994/05/20  12:58:14  pfeifer
  28.  * beta
  29.  *
  30.  * Revision 1.2  1994/03/08  21:07:19  pfeifer
  31.  * Patchlevel 04
  32.  *
  33.  * Revision 1.1  1993/02/16  15:05:35  freewais
  34.  * Initial revision
  35.  *
  36.  * Revision 1.3  92/02/12  13:58:52  jonathan
  37.  * Added "$Log" so RCS will put the log message in the header
  38.  * 
  39.  * 
  40.  * ported to Unix and SaberC -brewster 7/7/90
  41.  * added in bug fixes -Tracy 11/14/90
  42.  */
  43.  
  44. /*  
  45.  * INCLUDE EXTERNAL CONSTANTS                                         
  46.  */
  47.  
  48. #include "futil.h"
  49. #include <ctype.h> 
  50. #include "zprot.h"
  51. #include "zutil.h"
  52. #include "wprot.h"
  53. /* #include <string.h> */
  54. #include "cdialect.h"
  55. #include "wutil.h"
  56.  
  57.  
  58. /*  
  59.  * DEFINE LOCAL CONSTANTS
  60.  */
  61.  
  62.  
  63. #define CARRIAGE_RETURN 13
  64. #define LINE_FEED 10
  65. #define  ESC 27
  66. #define  DC1 17
  67. #define  DC3 19
  68. #define  ETS  3
  69.  
  70. #define FF  12
  71.  
  72.  
  73. #define INIT_CMD   1
  74. #define SEARCH_CMD 2
  75. #define EXTRACT_CMD 3
  76. #define STOP_CMD    4
  77.  
  78. #define MAX_CMD 4  /* init, query search, extract story, stop */
  79. #define MAX_BUFFER_LENGTH 10000 /* kludge -brewster */
  80.  
  81. /*
  82.  * DEFINE MACROS
  83.  */
  84.  
  85. #ifndef MINIMUM
  86. #define MINIMUM(a,b)  (a > b ? b : a)
  87. #endif
  88.  
  89. #define BIT(n)  (1L << n)
  90.  
  91. /*
  92.  * define global variables
  93.  */
  94.  
  95.  /* WAIS element names */
  96.     char *elm_name_tbl[] = {  ES_DocumentHeader
  97.                     ,ES_DocumentShortHeader
  98.                     ,ES_DocumentLongHeader
  99.                     ,ES_DocumentText
  100.                     ,ES_DocumentHeadline
  101.                     ,ES_DocumentCodes
  102.                     };
  103.  
  104. #ifdef TEST
  105.  
  106. twais_tmplt_typ1_srch_apdu _AP((char* buff,long* buff_len));
  107. twais_tmplt_typ3_srch_apdu _AP((char* buff,long* buff_len));
  108. dsply_doc_hdr_record _AP((WAISDocumentHeader* record));
  109. dsply_short_hdr_record _AP((WAISDocumentHeader* record));
  110.  
  111. main()
  112. {
  113.   char cmd[4096];
  114.   long cmd_len;
  115.  
  116.   printf("\n\n test template request apdu\n\n");
  117.  
  118.   do 
  119.     twais_format_req_apdu( TRUE, cmd, &cmd_len);
  120.   while ( cmd_len > 0 );
  121.  
  122.     
  123.  
  124.   printf("\n\n test formating request apdu\n\n");
  125.   do 
  126.     twais_format_req_apdu( FALSE, cmd, &cmd_len);
  127.   while ( cmd_len > 0 );
  128.  
  129.  
  130.   printf("\n\n test display init response apdu\n\n");
  131.  
  132.   twais_tmplt_init_rsp_apdu(  cmd, &cmd_len);
  133.   twais_dsply_rsp_apdu( cmd, cmd_len);
  134.  
  135.   printf("\n\n test display type3 search response apdu\n\n");
  136.   twais_tmplt_typ3_srch_rsp_apdu(  cmd, &cmd_len);
  137.   twais_dsply_rsp_apdu( cmd, cmd_len);
  138.  
  139.   printf("\n\n test display type1 search response apdu\n\n");
  140.   twais_tmplt_typ1_stry_rsp_apdu( cmd, &cmd_len);
  141.   twais_dsply_rsp_apdu( cmd, cmd_len);
  142.  
  143. }                /* main */
  144.  
  145. #endif
  146.  
  147.  
  148. static void get_int_item _AP((char* itm_name, long *itm_val));
  149.  
  150. static void
  151. get_int_item(itm_name, itm_val)
  152. char *itm_name;
  153. long  *itm_val;
  154. {
  155.   printf("    %s (integer): ", itm_name);
  156.   scanf("%ld", itm_val);
  157. }
  158.  
  159. static void get_str_item _AP((char* itm_name,char*  itm_val));
  160.  
  161. static void
  162. get_str_item(itm_name, itm_val)
  163. char *itm_name;
  164. char *itm_val;
  165. {
  166.   printf("    %s (string): ", itm_name);
  167.   scanf("%s", itm_val);
  168. }
  169.  
  170. static void get_line_item _AP((char* itm_name,char*  itm_val));
  171.  
  172. static void
  173. get_line_item(itm_name, itm_val)
  174. char *itm_name;
  175. char *itm_val;
  176. {
  177.    
  178.   printf("    %s (one line string):\n", itm_name);
  179. #ifdef _GETS__
  180.   fgets( itm_val,255,stdin);
  181.   if ( itm_val[0] == 0 )
  182.     fgets(itm_val,255,stdin);
  183. #else
  184.   gets( itm_val);
  185.   if ( itm_val[0] == 0 )
  186.     gets(itm_val);
  187. #endif
  188. }
  189.  
  190. static void get_req_type _AP((long* req_type));
  191.  
  192. static void
  193. get_req_type( req_type)
  194. long *req_type;
  195. {
  196.  
  197.   printf("\n\n");
  198.   printf(" request type 1)init  2)query search 3)extract story 4)stop: ");
  199.   scanf("%ld", req_type);
  200.  
  201. }                /* get_req_type */
  202.  
  203. /*
  204.  * "twais_format_req_apdu"  This function gets request message.  It reads the
  205.  *   request message into the the specified buffer.
  206.  *   It returns the the length of the data 
  207.  *   written into the buffer as an output parameter.  
  208.  *   A zero length value indicates "end session".
  209.  *
  210.  * return values:
  211.  *  none
  212.  */
  213. void 
  214. twais_format_req_apdu(use_template,apdu_buff,len)
  215. boolean use_template;
  216. char* apdu_buff;
  217. long* len;
  218. /* use_template :  (I) flag indicating whether use template apdu */
  219. /* apdu_buff    :  (O) buffer to put apdu */
  220. /* len          :  (O) number of bytes written to the buffer */
  221. {
  222.   long req_type;
  223.  
  224.   do { 
  225.  
  226.     get_req_type( &req_type);
  227.  
  228.     switch (req_type) {
  229.     case INIT_CMD: 
  230.       *len = twais_format_init_apdu( use_template, apdu_buff);
  231.       break;
  232.     case SEARCH_CMD: 
  233.       *len = twais_format_typ3_srch_apdu( use_template, apdu_buff);
  234.       break;
  235.     case EXTRACT_CMD: 
  236.       *len = twais_format_typ1_srch_apdu( use_template,  apdu_buff);
  237.       break;
  238.     case STOP_CMD: 
  239.       *len = 0;
  240.       break;
  241.     default: 
  242.       break;
  243.     
  244.     }                /* end switch */
  245.   }  
  246.   while ( req_type < 1 || req_type > MAX_CMD );
  247.  
  248. }                /* twais_format_req_apdu */
  249.  
  250.  
  251.  
  252. /*
  253.  * "twais_format_init_apdu"
  254.  *   prompt user information to format an init apdu and 
  255.  *   write the apdu to the specified buffer
  256.  *
  257.  * function return:
  258.  *   number of bytes written to the buffer 
  259.  */
  260. long 
  261. twais_format_init_apdu(use_template,apdu_buff)
  262. boolean use_template;
  263. char* apdu_buff;
  264.  
  265. /* use_template :  (I) flag indicating whether use template apdu */
  266. /* apdu_buff    :  (O) buffer to put apdu */
  267. {
  268.   InitAPDU *init1;
  269.   char  *end_ptr;
  270.   long len;
  271.   long pref_msg_size;
  272.   long max_rec_size;
  273.   any refID;
  274.   char ref_id[128];
  275.  
  276.   if ( use_template ) {
  277.     twais_tmplt_init_apdu(apdu_buff, &len);
  278.     return( len);
  279.   }      
  280.  
  281.   get_int_item( "prefered message size", &pref_msg_size);
  282.   get_int_item( "maximum record size", &max_rec_size);
  283.  
  284.   get_str_item("reference id", ref_id);
  285.   refID.size = strlen(ref_id);
  286.   refID.bytes = &ref_id[0];
  287.  
  288.   init1 = makeInitAPDU(WILL_USE,WILL_NOT_USE,WILL_NOT_USE,WILL_NOT_SUPPORT,
  289.                        WILL_NOT_SUPPORT,
  290.                        pref_msg_size,
  291.                        max_rec_size, NULL,
  292.                        defaultImplementationID(),defaultImplementationName(),
  293.                        defaultImplementationVersion(), &refID,NULL);
  294.  
  295.   { long buffer_len = MAX_BUFFER_LENGTH;
  296.     end_ptr = writeInitAPDU(init1, apdu_buff, &buffer_len);
  297.   }
  298.   freeInitAPDU(init1);
  299.   len = (long)end_ptr - (long)apdu_buff;
  300.   return(len);  
  301. }                /* twais_format_init_apdu */
  302.  
  303. /* 
  304.  * "twais_format_typ3_srch_apdu"  
  305.  *  prompt user information to form a relevance feedback search apdu and
  306.  *  write the apdu to the specified buffer
  307.  *
  308.  * function return:
  309.  *   number of bytes written to the buffer 
  310.  */
  311. long 
  312. twais_format_typ3_srch_apdu(use_template,apdu_buff)
  313. boolean use_template;
  314. char* apdu_buff;
  315.  
  316. /* use_template :  (I) flag indicating whether use template apdu */
  317. /* apdu_buff    :  (O) buffer to put apdu */
  318. {
  319.   SearchAPDU *search;
  320.   char  *end_ptr;
  321.   long len;
  322.   long small, large, medium;
  323.  
  324.   char temp_string[80];
  325.  
  326.   long num_databases, num_elmsets, i;
  327.   char **database_names_ptr;
  328.   char *database_names[11];
  329.   char database_name[10][129];
  330.   long  elm_type;
  331.   char *elm_names[21];
  332.   char elm_name[20][128];
  333.   char **elm_names_ptr = &elm_names[0];
  334.  
  335.   any refID;
  336.   char ref_id[256];
  337.   char seed_words[257];
  338.  
  339.   DocObj *DocObjs[5];
  340.  
  341.   DocObj **DocObjsPtr = 0;
  342.   long DateFactor;
  343.   char BeginDateRange[9], EndDateRange[9];
  344.   long maxDocsRetrieved;
  345.   long num, sw;
  346.   char doc_id[4][200];
  347.   any docID[4];
  348.   long ChunkCode;
  349.   any Start[4], End[4];   
  350.   char start_pos[4][10], end_pos[4][10];
  351.   long start_ipos, end_ipos;
  352.   WAISSearch *query;
  353.   long count;
  354.   for(count = 0; count < 5; count++){
  355.     DocObjs[count] = 0;        /* added by brewster */
  356.   }
  357.  
  358.   if ( use_template ) {
  359.     twais_tmplt_typ3_srch_apdu(apdu_buff, &len);
  360.     return( len);
  361.   }      
  362.  
  363.  
  364.   get_int_item("small set upper bound", &small);
  365.   get_int_item("large set lower bound", &large);
  366.   get_int_item("medium set present number", &medium);
  367.  
  368.   get_int_item("number of databases(max 10, 0 search entire databases)", &num_databases);
  369.  
  370.   if ( num_databases == 0 ) {
  371.     database_names_ptr = 0;
  372.   }
  373.  
  374.   else {
  375.     database_names_ptr = &database_names[0];
  376.     database_names[num_databases] = 0;  
  377.     for ( i=0; i < num_databases; i++ ) {
  378.       database_names[i] = &database_name[i][0];
  379.       sprintf( temp_string,"database name %ld", (i+1) );
  380.       get_str_item(temp_string, database_name[i]);
  381.     }
  382.   }
  383.  
  384.   get_int_item("number of database-element_set pairs(max 10)", &num_elmsets);
  385.  
  386.   if ( num_elmsets == 0 ) 
  387.     elm_names_ptr = 0;
  388.   else {
  389.     elm_names[num_elmsets * 2 ] = 0;
  390.     for ( i=0; i < num_elmsets; i++ ) {
  391.       elm_names[i*2] = &elm_name[i*2][0];
  392.       sprintf( temp_string,"database name %ld", (i+1) );
  393.       get_str_item(temp_string, &elm_name[i*2][0]);
  394.  
  395.       get_int_item("  element type 0)default 1)DocHeaders 2)ShortHeaders\n        3)LongHeaders 4)Text 5)HeadLines 6)Codes", 
  396.            &elm_type);
  397.       if ( (elm_type < 1) || (elm_type > 6) )
  398.     elm_type = 1;
  399.       elm_names[i*2+1] = &elm_name[i*2+1][0];
  400.       strcpy( &elm_name[i*2+1][0], elm_name_tbl[elm_type-1]);
  401.     }
  402.   }
  403.  
  404.  
  405.   get_str_item("reference id", ref_id);
  406.   refID.size = strlen(ref_id);
  407.   refID.bytes = &ref_id[0];
  408.  
  409.   /*
  410.    * format wais search query
  411.    */
  412.   /* fill in the user information */
  413.  
  414.   get_line_item("seed_words", seed_words);
  415.   get_int_item("number of relevance feedback documents(max 4)", &num);
  416.   if ( num > 0 ) {
  417.  
  418.     if ( num > 4 )
  419.       num = 4;
  420.     DocObjsPtr = &DocObjs[0];
  421.     for ( i=0; i< num; i++) {
  422.       docID[i].bytes = &doc_id[i][0];
  423.       sprintf(temp_string, "document id %ld", (i+1));
  424.       get_str_item(temp_string, &doc_id[i][0]);
  425.       docID[i].size = strlen( &doc_id[i][0]);
  426.       get_int_item("  (1)whole story (2)part story", &sw);
  427.       if ( sw == 1) {
  428.     DocObjs[i] = makeDocObjUsingWholeDocument( &docID[i],NULL);
  429.       }
  430.       else {
  431.     get_int_item("  ChunkCode (1)byte (2)line (3)parag", &ChunkCode);
  432.     if ( ChunkCode == 1 ) {
  433.       get_int_item("  start position", &start_ipos);
  434.       get_int_item("  end position", &end_ipos);
  435.       DocObjs[i] = makeDocObjUsingBytes( &docID[i], NULL,
  436.                         start_ipos, end_ipos);
  437.     }
  438.     else if ( ChunkCode == 2 ) {
  439.       get_int_item("  start position", &start_ipos);
  440.       get_int_item("  end position", &end_ipos);
  441.       DocObjs[i] = makeDocObjUsingLines( &docID[i], NULL,
  442.                         start_ipos, end_ipos);
  443.     }
  444.     else {
  445.       get_str_item("  start position", &start_pos[i][0]);
  446.       get_str_item("  end position", &end_pos[i][0]);
  447.       Start[i].size = strlen( &start_pos[i][0]);
  448.       Start[i].bytes = &start_pos[i][0];
  449.       End[i].size = strlen( &end_pos[i][0]);
  450.       End[i].bytes = &end_pos[i][0];
  451.       DocObjs[i] = makeDocObjUsingParagraphs( &docID[i], NULL,
  452.                          &Start[i], &End[i]);
  453.     }
  454.       }                /* end if-else */
  455.     }                /* end for */
  456.   }                /* end if */
  457.    
  458.   get_int_item("DateFactor (1-independent,2-later,3-earlier,4-range)", &DateFactor);
  459.   if ( DateFactor == 2 || DateFactor == 4) 
  460.     get_str_item("begin date  (yyyymmdd)", BeginDateRange);
  461.   else
  462.     BeginDateRange[0] = '\0';
  463.   if ( DateFactor == 3 || DateFactor == 4) 
  464.     get_str_item("end date (yyyymmdd)", EndDateRange);
  465.   else
  466.     EndDateRange[0] = '\0';
  467.  
  468.   get_int_item("max. documents retrieved", &maxDocsRetrieved);
  469.  
  470.   query = makeWAISSearch( seed_words, DocObjsPtr, 0L,
  471.              DateFactor, BeginDateRange, EndDateRange,
  472.              maxDocsRetrieved);
  473.  
  474.   search = makeSearchAPDU( small, large, medium, 
  475.               1L,    /* replace indicator */
  476.               "FOO", /* result set name */
  477.               database_names_ptr, /* database name */   
  478.               QT_RelevanceFeedbackQuery, /* query_type */
  479.               elm_names_ptr, /* element name */
  480.               &refID, query);
  481.  
  482.   {
  483.     long buffer_len = MAX_BUFFER_LENGTH;
  484.     end_ptr = writeSearchAPDU(search, apdu_buff, &buffer_len);
  485.   }
  486.   len = (long)end_ptr - (long)apdu_buff;
  487.  
  488.   i =0;
  489.   while ( DocObjs[i] != 0 ) {
  490.     CSTFreeDocObj( DocObjs[i]);
  491.     i++;
  492.   }
  493.  
  494.   CSTFreeWAISSearch(query);
  495.  
  496.   freeSearchAPDU(search);
  497.  
  498.   return(len);
  499.  
  500. }                /* twais_format_typ3_srch_apdu */
  501.  
  502. /* 
  503.  * "twais_format_typ1_srch_apdu"  
  504.  *  prompt user information to form a text retrieval search apdu and
  505.  *  write the apdu to the specified buffer
  506.  *
  507.  * function return:
  508.  *   number of bytes written to the buffer 
  509.  */
  510. long
  511. twais_format_typ1_srch_apdu(use_template,apdu_buff)
  512. boolean use_template;
  513. char* apdu_buff;
  514.  
  515. /* use_template :  (I) flag indicating whether use template apdu */
  516. /* apdu_buff    :  (O) buffer to put apdu */
  517. {
  518.   SearchAPDU *search;
  519.   char  *end_ptr;
  520.   long len;
  521.   long small, large, medium;
  522.  
  523.   char temp_string[80];
  524.  
  525.   long num_databases, num_elmsets, i;
  526.   char **database_names_ptr;
  527.   char *database_names[11];
  528.   char database_name[10][129];
  529.   long  elm_type;
  530.   char *elm_names[21];
  531.   char elm_name[20][128];
  532.   char **elm_names_ptr = &elm_names[0];
  533.  
  534.   any refID;
  535.   char ref_id[256];
  536.  
  537.   any *query;            /* changed by brewster from char * */
  538.   DocObj *DocObjs[11];
  539.   long num_doc;
  540.   long sw;
  541.   char doc_id[10][200];
  542.   any docID[10];
  543.   long ChunkCode;
  544.   any Start[10], End[10];   
  545.   long start_ipos, end_ipos;
  546.   char start_pos[10][10], end_pos[10][10];
  547.  
  548.   long use_text = 0;
  549.  
  550.  
  551.   if ( use_template ) {
  552.     twais_tmplt_typ1_srch_apdu(apdu_buff, &len);
  553.     return( len);
  554.   }      
  555.  
  556.  
  557.   get_int_item("small set upper bound", &small);
  558.   get_int_item("large set lower bound", &large);
  559.   get_int_item("medium set present number", &medium);
  560.  
  561.   get_int_item("number of databases(max 10, 0 search entire databases)", &num_databases);
  562.  
  563.   if ( num_databases == 0 ) {
  564.     database_names_ptr = 0;
  565.   }
  566.   else {
  567.     database_names_ptr = &database_names[0];
  568.     database_names[num_databases] = 0;  
  569.     for ( i=0; i < num_databases; i++ ) {
  570.       database_names[i] = &database_name[i][0];
  571.       sprintf(temp_string, "database name %ld", (i+1));
  572.       get_str_item( temp_string, database_name[i]);
  573.     }
  574.   }
  575.  
  576.   get_int_item("number of database-element_set pairs(max 10)", &num_elmsets);
  577.  
  578.   if ( num_elmsets == 0 ) 
  579.     elm_names_ptr = 0;
  580.   else {
  581.     elm_names[num_elmsets * 2 ] = 0;
  582.     for ( i=0; i < num_elmsets; i++ ) {
  583.       elm_names[i*2] = &elm_name[i*2][0];
  584.       sprintf( temp_string,"database name %ld", (i+1) );
  585.       get_str_item(temp_string, &elm_name[i*2][0]);
  586.  
  587.       get_int_item("  element type 0)default 1)DocHeaders 2)ShortHeaders\n        3)LongHeaders 4)Text 5)HeadLines 6)Codes", 
  588.            &elm_type);
  589.       if ( (elm_type < 1) || (elm_type > 6) )
  590.     elm_type = 1;
  591.       if ( elm_type == 4)  use_text++;
  592.       elm_names[i*2+1] = &elm_name[i*2+1][0];
  593.       strcpy( &elm_name[i*2+1][0], elm_name_tbl[elm_type-1]);
  594.     }
  595.   }
  596.  
  597.   get_str_item("reference id", ref_id);
  598.   refID.size = strlen(ref_id);
  599.   refID.bytes = &ref_id[0];
  600.  
  601.   /*
  602.    * format type 1 query
  603.    */
  604.   get_int_item("num of documents to retrieve (max 10)", &num_doc);
  605.   if ( num_doc > 10 ) num_doc = 10;
  606.   if ( num_doc < 1 ) num_doc = 1;
  607.  
  608.   DocObjs[num_doc] = 0;
  609.  
  610.   for ( i=0; i < num_doc; i++ ) {
  611.     docID[i].bytes = &doc_id[i][0];
  612.  
  613.     sprintf( temp_string, "document id %ld", (i+1));
  614.     get_str_item(temp_string, &doc_id[i][0]);
  615.     docID[i].size = strlen( &doc_id[i][0]);
  616.         
  617.     if ( use_text == 0 )
  618.       DocObjs[i] = makeDocObjUsingWholeDocument( &docID[i],NULL);
  619.     else {         
  620.       get_int_item("  (1)whole story (2)part story", &sw);
  621.       if ( sw == 1) {
  622.     DocObjs[i] = makeDocObjUsingWholeDocument( &docID[i],NULL);
  623.       }
  624.       else {
  625.     get_int_item("  ChunkCode (1)byte (2)line (3)parag", &ChunkCode);
  626.     if ( ChunkCode == 1 ) {
  627.       get_int_item("  start position", &start_ipos);
  628.       get_int_item("  end position", &end_ipos);
  629.       DocObjs[i] = makeDocObjUsingBytes( &docID[i], NULL,
  630.                         start_ipos, end_ipos);
  631.     }
  632.     else if ( ChunkCode == 2 ) {
  633.       get_int_item("  start position", &start_ipos);
  634.       get_int_item("  end position", &end_ipos);
  635.       DocObjs[i] = makeDocObjUsingLines( &docID[i], NULL,
  636.                         start_ipos, end_ipos);
  637.     }
  638.     else {
  639.       get_str_item("  start position", &start_pos[i][0]);
  640.       get_str_item("  end position", &end_pos[i][0]);
  641.       Start[i].size = strlen( &start_pos[i][0]);
  642.       Start[i].bytes = &start_pos[i][0];
  643.       End[i].size = strlen( &end_pos[i][0]);
  644.       End[i].bytes = &end_pos[i][0];
  645.       DocObjs[i] = makeDocObjUsingParagraphs( &docID[i], NULL,
  646.                          &Start[i], &End[i]);
  647.     }
  648.       }                /* end if-else */
  649.     }
  650.   }
  651.  
  652.   query = makeWAISTextQuery(DocObjs);   
  653.  
  654.  
  655.   search = makeSearchAPDU( small, large, medium, 
  656.               1L,    /* replace indicator */
  657.               "FOO", /* result set name */
  658.               database_names_ptr, /* database name */   
  659.               QT_TextRetrievalQuery, /* query_type */
  660.               elm_names_ptr, /* element name */
  661.               &refID, query);
  662.  
  663.   {
  664.     long buffer_len = MAX_BUFFER_LENGTH;
  665.     end_ptr = writeSearchAPDU(search, apdu_buff, &buffer_len);
  666.   }
  667.   len = (long)end_ptr - (long)apdu_buff;
  668.  
  669.   i =0;
  670.   while ( DocObjs[i] != 0) {
  671.     CSTFreeDocObj( DocObjs[i]);
  672.     i++;
  673.   }
  674.  
  675.   CSTFreeWAISTextQuery( query);
  676.  
  677.   freeSearchAPDU(search);
  678.  
  679.   return(len);
  680.  
  681. }                /* twais_format_typ1_srch_apdu */
  682.  
  683. static void print_hdline _AP((char* hdline));
  684.  
  685. static void print_hdline(hdline)
  686. char *hdline;
  687. {
  688.   char buf[301];
  689.   long len, i;
  690.  
  691.   len = strlen(hdline);
  692.   if (len > 300 )
  693.     len =300;
  694.   for ( i=0; i< len; i++ )
  695.     if ( hdline[i] > 31 && hdline[i] < 127 )
  696.       buf[i] = hdline[i];
  697.     else
  698.       buf[i] = '@';         
  699.   buf[i] = 0;
  700.   printf("     Headline:  %s\n", buf);
  701. }
  702.  
  703.  
  704. static void print_any _AP((char* title,any*  any_ptr));
  705.  
  706. static void print_any( title, any_ptr)
  707. char *title;
  708. any *any_ptr;
  709. {
  710.   long i;
  711.   printf("%s", title);
  712.   if ( any_ptr ) {
  713.     for ( i=0; i < any_ptr->size; i++)
  714.      { if (isprint(any_ptr->bytes[i]))
  715.      printf("%c", any_ptr->bytes[i]);
  716.        else
  717.      printf("%ld", (long)any_ptr->bytes[i]);
  718.      }
  719.     printf("\n");
  720.   } 
  721. }
  722.  
  723.  
  724.   
  725. static void dsply_long_hdr_record _AP((WAISDocumentLongHeader* record));
  726.  
  727. static void dsply_long_hdr_record(record)
  728. WAISDocumentLongHeader *record;
  729. /*
  730.  * 'dsply_long_hdr_record'
  731.  *   display one WAIS long header  record 
  732.  */
  733. {
  734.   printf(" LongHeaders\n");
  735.  
  736.   print_any("     DocumentID:  ", record->DocumentID);
  737.  
  738.   printf("     VersionNumber:  %ld\n", record->VersionNumber);
  739.  
  740.   printf("     Score:  %ld,  BestMatch:  %ld\n", 
  741.      record->Score,
  742.      record->BestMatch);
  743.  
  744.   printf("     DocumentLength:  %ld,  Lines:  %ld\n", 
  745.      record->DocumentLength,
  746.      record->Lines);
  747.  
  748.   if ( record->Source )
  749.     printf("     Source:  %s\n", record->Source);
  750.  
  751.   if ( record->Date )
  752.     printf("     Date:  %s\n", record->Date);
  753.  
  754.   if ( record->OriginCity)
  755.     printf("     OriginCity:  %s\n", record->OriginCity);
  756.  
  757.   if ( record->Headline)
  758. #ifdef FOR_DUM_TERM
  759.     print_hdline(record->Headline);
  760. #else
  761.   printf("     Headline:  %s\n", record->Headline);
  762. #endif
  763.  
  764.   if ( record->StockCodes)
  765.     printf("     StockCodes:  %s", record->StockCodes);
  766.  
  767.   if ( record->CompanyCodes )
  768.     printf("     CompanyCodes:  %s", record->CompanyCodes);
  769.  
  770.   if ( record->IndustryCodes)
  771.     printf("     IndustryCodes:  %s", record->IndustryCodes);
  772.  
  773.   printf("\n");
  774. }
  775. /*
  776.  * dsply_text
  777.  *  display story text
  778.  */
  779. #define TEXT_LINES_PER_PAGE 18
  780. #define  DQ_PAR_LEN   3
  781. #define  DQ_EOL_LEN   1
  782. #define  DQ_MAX_LINE_LEN  256
  783.  
  784. #define  PRINT_LINE(line, ndx, line_cnt,text_ptr,last_ptr,continue_viewing)\
  785.          line[ndx] = NULL;\
  786.          line_cnt++; \
  787.          printf("%s\n", line);\
  788.          ndx = 0;\
  789.          if ( (line_cnt == TEXT_LINES_PER_PAGE) && (text_ptr <= last_ptr)) {\
  790.             line_cnt = 0;\
  791.             printf("\n  ... more to come, enter 1 to continue or 0 to stop: ");\
  792.             scanf("%ld", &continue_viewing);\
  793.             }
  794.  
  795. #if 0
  796. /*
  797.  * try to format text
  798.  */
  799. dsply_text( size, text)
  800. long size;
  801. char *text;
  802. {
  803.   char  line[DQ_MAX_LINE_LEN +1];
  804.   char *last_ptr;
  805.   char *text_ptr;
  806.   long  ndx;
  807.   long line_cnt = 0;
  808.   long continue_viewing = 1;
  809.     
  810.   text_ptr = text;
  811.  
  812.   last_ptr = text_ptr + size;
  813.  
  814.   while ( (*text_ptr != ETS) && (text_ptr < last_ptr) ) {
  815.     if (  *text_ptr++ == ESC ) {
  816.       if (*text_ptr++ == 'k') 
  817.     break;
  818.     }
  819.   }
  820.  
  821.   if ( text_ptr >= last_ptr ) {
  822.     printf("**** ERROR in display text -- could not find text\n");
  823.     return;
  824.   }
  825.  
  826.   ndx = 0;
  827.  
  828.   while ( (continue_viewing == 1) && ( *text_ptr != ETS) &&
  829.      (text_ptr < last_ptr) ) {
  830.  
  831.     /* paragraph id -- skip */
  832.     if ( *text_ptr == ESC) {
  833.       text_ptr++;
  834.       if ( *text_ptr == 'l' )
  835.     text_ptr++;
  836.       if ( ndx > 0 ) {
  837.     PRINT_LINE(line, ndx,line_cnt,text_ptr,last_ptr,continue_viewing);  
  838.       }
  839.       ndx = DQ_PAR_LEN;
  840.       strncpy( line, text_ptr, ndx);
  841.       text_ptr += DQ_PAR_LEN;
  842.       PRINT_LINE(line, ndx,line_cnt,text_ptr,last_ptr,continue_viewing);  
  843.     }
  844.  
  845.     /* highlight & dehighlight markers -- skip */
  846.     else if ( (*text_ptr == DC1) || (*text_ptr == DC3) ) 
  847.       text_ptr++;
  848.  
  849.     /* CR -- skip and print */
  850.     else if ( *text_ptr == CARRIAGE_RETURN ) {
  851.       text_ptr += DQ_EOL_LEN;    /* CR, LF */
  852.       PRINT_LINE(line, ndx, line_cnt,text_ptr,last_ptr,continue_viewing);
  853.     }
  854.  
  855.     else {
  856.       line[ndx++] = *text_ptr++;
  857.       if ( ndx > DQ_MAX_LINE_LEN ) {
  858.     printf("**** ERROR in display text -- line too long %ld\n", ndx);
  859.     return;
  860.       }
  861.     }
  862.   }                /* end while */
  863.  
  864.   if ( text_ptr >= last_ptr ) {
  865.     printf("**** ERROR in display text -- could not find End Of Text\n");
  866.     return;
  867.   }
  868.  
  869.   if ( ndx > 0 ) {
  870.     line[ndx] = NULL;
  871.     line_cnt++; 
  872.     printf("%s\n", line);
  873.   }
  874.  
  875.  
  876. }                /* dsply_text */
  877. #endif
  878.  
  879. static void dsply_text _AP((long size,char* text));
  880.  
  881. static void dsply_text( size, text)
  882. long size;
  883. char *text;
  884. {
  885.   char *text_ptr, *last_ptr;
  886.   long line_cnt = 0;
  887.   long continue_viewing = 1;
  888.   char buff[3200];
  889.   long len;
  890.   char *buff_start, *buff_ptr;
  891.     
  892.   text_ptr = text;
  893.  
  894.   buff_start = &buff[0];    
  895.   buff_ptr = buff_start;
  896.   
  897.   last_ptr = text_ptr + size;
  898.  
  899.   while ( (text_ptr <= last_ptr) && (continue_viewing == 1) ) {
  900.     /* control markers */
  901.     if (  *text_ptr == ESC ) {
  902.       text_ptr++;
  903.       text_ptr++;
  904.     }
  905.     /* highlight & dehighlight markers -- skip */
  906.     else if (*text_ptr == DC1 || *text_ptr == DC3)
  907.       text_ptr++;
  908.     else if (*text_ptr == ETS)
  909.       text_ptr++;
  910.     else if ( *text_ptr == CARRIAGE_RETURN ) {
  911.       text_ptr++;        /* CR */
  912.       *buff_ptr++= CARRIAGE_RETURN;
  913.       *buff_ptr++ = LINE_FEED;
  914.       line_cnt++;
  915.       if ( (line_cnt == TEXT_LINES_PER_PAGE) && 
  916.       (text_ptr <= last_ptr)) {
  917.     len = (long)buff_ptr - (long) buff_start;
  918.     fwrite( buff_start, len, 1, stdout);
  919.     line_cnt = 0;
  920.     buff_ptr = buff_start;
  921.     printf("\n  ... more to come, enter 1 to continue or 0 to stop: ");
  922.     scanf("%ld", &continue_viewing);
  923.       }
  924.     }
  925.     else 
  926.       *buff_ptr++ = *text_ptr++;
  927.   }                /* end while */
  928.  
  929.   if ( buff_ptr > buff_start) {
  930.     len = (long)buff_ptr - (long)buff_start;
  931.     fwrite( buff_start, len,  1, stdout);
  932.   }
  933.  
  934. }                /* dsply_text */
  935.  
  936. static void dsply_text_record _AP((WAISDocumentText*  record));
  937.  
  938. static void dsply_text_record( record)
  939. WAISDocumentText *record;
  940. /*
  941.  * 'dsply_text_record'
  942.  *   display one WAIS text record 
  943.  */
  944. {
  945.   printf(" Text\n");
  946.   print_any("     DocumentID:  ", record->DocumentID);
  947.  
  948.   printf("     VersionNumber:  %ld\n", record->VersionNumber);
  949.   dsply_text( record->DocumentText->size,
  950.          record->DocumentText->bytes);
  951. }
  952.  
  953. static void dsply_headline_record _AP((WAISDocumentHeadlines*  record));
  954.  
  955. static void dsply_headline_record( record)
  956. WAISDocumentHeadlines *record;
  957. /*
  958.  * 'dsply_headline_record'
  959.  *   display one WAIS headline record 
  960.  */
  961. {
  962.   printf(" Headlines\n");
  963.   print_any("     DocumentID:  ", record->DocumentID);
  964.  
  965.   printf("     VersionNumber:  %ld\n", record->VersionNumber);
  966.  
  967.   if ( record->Source )
  968.     printf("     Source:  %s\n", record->Source);
  969.  
  970.   if ( record->Date )
  971.     printf("     Date:  %s\n", record->Date);
  972.  
  973.   if ( record->OriginCity)
  974.     printf("     OriginCity:  %s\n", record->OriginCity);
  975.   print_hdline(record->Headline);
  976.  
  977.   if ( record->Headline)
  978. #ifdef FOR_DUM_TERM
  979.     print_hdline(record->Headline);
  980. #else
  981.   printf("     Headline:  %s\n", record->Headline);
  982. #endif
  983. }
  984.  
  985. static void dsply_code_record _AP((WAISDocumentCodes*  record));
  986.  
  987. static void dsply_code_record( record)
  988. WAISDocumentCodes  *record;
  989. /*
  990.  * 'dsply_code_record'
  991.  *   display one WAIS code record 
  992.  */
  993. {
  994.   printf(" Codes\n");
  995.   print_any("     DocumentID:  ", record->DocumentID);
  996.  
  997.   printf("     VersionNumber:  %ld\n", record->VersionNumber);
  998.  
  999.   if ( record->StockCodes)
  1000.     printf("     StockCodes:  %s", record->StockCodes);
  1001.  
  1002.   if ( record->CompanyCodes )
  1003.     printf("     CompanyCodes:  %s", record->CompanyCodes);
  1004.  
  1005.   if ( record->IndustryCodes)
  1006.     printf("     IndustryCodes:  %s", record->IndustryCodes);
  1007.  
  1008.   printf("\n");
  1009. }
  1010.  
  1011.  
  1012. /*
  1013.  * "twais_dsply_rsp_apdu"
  1014.  *   display response apdu on stdout
  1015.  *   the response apdu is in the specified buffer
  1016.  */
  1017. void
  1018. twais_dsply_rsp_apdu(rsp_buff, rsp_len)
  1019. char *rsp_buff;         /* (I) buffer contain response apdu */
  1020. long  rsp_len;           /* (I) number of bytes in the buffer */
  1021. {
  1022.  
  1023.   pdu_type pdu;
  1024.   pdu = peekPDUType(rsp_buff);
  1025.   switch ( pdu) {
  1026.   case initResponseAPDU:
  1027.     twais_dsply_init_rsp_apdu( rsp_buff);
  1028.     break;
  1029.   case searchResponseAPDU:
  1030.     twais_dsply_srch_rsp_apdu( rsp_buff);
  1031.     break;
  1032.  
  1033.   case initAPDU:
  1034.     twais_dsply_init_apdu( rsp_buff);
  1035.     break;
  1036.   case searchAPDU:
  1037.     twais_dsply_srch_apdu( rsp_buff);
  1038.     break;
  1039.   default:
  1040.     /* others not supported yet */
  1041.     break;
  1042.   }
  1043.  
  1044. }                /* twais_dsply_rsp_apdu */
  1045.  
  1046.  
  1047. /*
  1048.  * "twais_dsply_init_rsp_apdu"
  1049.  *   display init response apdu on stdout
  1050.  *   the response apdu is encoded in the specified buffer
  1051.  */
  1052. void
  1053. twais_dsply_init_rsp_apdu( buffer)
  1054. char *buffer;           /* (I) buffer contain the init response apdu */
  1055. {
  1056.  
  1057.   InitResponseAPDU *response;
  1058.   WAISInitResponse *info;
  1059.   long i, len;
  1060.  
  1061.   printf("\n\n Init Response:\n");
  1062.  
  1063.   readInitResponseAPDU(&response,buffer);
  1064.  
  1065.   printf("    willSearch: %ld,  willPresent: %ld,  willDelete: %ld\n", 
  1066.      response->willSearch, 
  1067.      response->willPresent,
  1068.      response->willDelete);
  1069.   printf("    supportAccessControl: %ld,  supportResourceControl: %ld\n",
  1070.      response->supportAccessControl,
  1071.      response->supportResourceControl);
  1072.   printf("    PreferredMessageSize: %ld,  MaximumRecordSize: %ld\n",
  1073.      response->PreferredMessageSize, 
  1074.      response->MaximumRecordSize);
  1075.   if ( response->ImplementationID != 0) {
  1076.     printf("    ImplementationID: %s\n", 
  1077.        response->ImplementationID);   
  1078.   }
  1079.   if ( response->ImplementationName != 0) {
  1080.     printf("    ImplementationName: %s\n",
  1081.        response->ImplementationName);   
  1082.   }
  1083.   if ( response->ImplementationVersion != 0) {
  1084.     printf("    ImplementationVersion: %s\n",
  1085.        response->ImplementationVersion);   
  1086.   }
  1087.   if ( response->ReferenceID != 0) {
  1088.     print_any("    ReferenceID: ", response->ReferenceID);
  1089.   }
  1090.  
  1091.   if ( response->UserInformationField != 0) {
  1092.     info = (WAISInitResponse *)response->UserInformationField;
  1093.     printf("    ChunkCode: %ld,  ChunkIDLength: %ld\n",
  1094.        info->ChunkCode,
  1095.        info->ChunkIDLength);
  1096.  
  1097.     printf("    ChunkMarker: ");
  1098.     len = strlen( info->ChunkMarker);
  1099.     for ( i=0; i< len; i++)
  1100.       printf("%ld, ", info->ChunkMarker[i]);
  1101.     printf("\n");
  1102.  
  1103.     printf("    HighlightMarker: ");
  1104.     len = strlen( info->HighlightMarker);
  1105.     for ( i=0; i< len; i++)
  1106.       printf("%ld, ", info->HighlightMarker[i]);
  1107.     printf("\n");
  1108.  
  1109.     printf("    DeHighlightMarker: ");
  1110.     len = strlen( info->DeHighlightMarker);
  1111.     for ( i=0; i< len; i++)
  1112.       printf("%ld, ", info->DeHighlightMarker[i]);
  1113.     printf("\n");
  1114.  
  1115.     printf("    NewlineCharacters: ");
  1116.     len = strlen( info->NewlineCharacters);
  1117.     for ( i=0; i< len; i++)
  1118.       printf("%ld, ", info->NewlineCharacters[i]);
  1119.     printf("\n");
  1120.  
  1121.   }
  1122.   freeInitResponseAPDU( response);
  1123.  
  1124. }                /* twais_dsply_init_rsp_apdu */
  1125.  
  1126. /*
  1127.  * "twais_dsply_init_apdu"
  1128.  *   display init apdu on stdout
  1129.  *   the apdu is in the specified buffer
  1130.  */
  1131. void
  1132. twais_dsply_init_apdu( buffer)
  1133. char *buffer;           /* (I) buffer contain the init response apdu */
  1134. {
  1135.  
  1136.   InitAPDU *init;
  1137.  
  1138.   printf("\n\n Init Request:\n");
  1139.  
  1140.   readInitAPDU(&init,buffer);
  1141.  
  1142.   printf("    willSearch: %ld,  willPresent: %ld,  willDelete: %ld\n", 
  1143.      init->willSearch, 
  1144.      init->willPresent,
  1145.      init->willDelete);
  1146.   printf("    supportAccessControl: %ld,  supportResourceControl: %ld\n",
  1147.      init->supportAccessControl,
  1148.      init->supportResourceControl);
  1149.   printf("    PreferredMessageSize: %ld,  MaximumRecordSize: %ld\n",
  1150.      init->PreferredMessageSize, 
  1151.      init->MaximumRecordSize);
  1152.  
  1153.   if ( init->IDAuthentication != 0) {
  1154.     printf("    IDAuthentication: %s\n", 
  1155.        init->IDAuthentication);   
  1156.   }
  1157.  
  1158.   if ( init->ImplementationID != 0) {
  1159.     printf("    ImplementationID: %s\n", 
  1160.        init->ImplementationID);   
  1161.   }
  1162.  
  1163.   if ( init->ImplementationName != 0) {
  1164.     printf("    ImplementationName: %s\n",
  1165.        init->ImplementationName);   
  1166.   }
  1167.  
  1168.   if ( init->ImplementationVersion != 0) {
  1169.     printf("    ImplementationVersion: %s\n",
  1170.        init->ImplementationVersion);   
  1171.   }
  1172.  
  1173.   if ( init->ReferenceID != 0) {
  1174.     print_any("    ReferenceID: ", init->ReferenceID);
  1175.   }
  1176.  
  1177.   freeInitAPDU( init);
  1178.  
  1179. }                /* twais_dsply_init_apdu */
  1180.  
  1181. /*
  1182.  * "twais_dsply_srch_rsp_apdu"
  1183.  *   display search response apdu on stdout
  1184.  *   the response apdu is encoded in the specified buffer
  1185.  */
  1186. void
  1187. twais_dsply_srch_rsp_apdu( buffer)
  1188. char *buffer;           /* (I) buffer contain the search response apdu */
  1189. {
  1190.   SearchResponseAPDU  *response;
  1191.   WAISSearchResponse  *info;
  1192.   long continue_viewing;
  1193.   long i, k;
  1194.  
  1195.   printf("\n\n Search Response:\n");
  1196.  
  1197.   readSearchResponseAPDU(&response,buffer);
  1198.   printf("    SearchStatus:            %ld\n", response->SearchStatus); 
  1199.   printf("    ResultCount:             %ld\n", response->ResultCount); 
  1200.   printf("    NumberOfRecordsReturned: %ld\n", response->NumberOfRecordsReturned); 
  1201.   printf("    PresentStatus:           %ld\n", response->PresentStatus); 
  1202.   if ( response->ReferenceID != 0 )
  1203.     print_any("    ReferenceID:             ", response->ReferenceID);
  1204.  
  1205.   if ( response->DatabaseDiagnosticRecords != 0 ) {
  1206.     info = (WAISSearchResponse *)response->DatabaseDiagnosticRecords;
  1207.     if ( info->SeedWordsUsed != 0 )
  1208.       printf("    SeedWordsUsed:           %s\n", info->SeedWordsUsed); 
  1209.  
  1210.     i =0; 
  1211.     continue_viewing = 1; 
  1212.  
  1213.     if ( info->DocHeaders != 0 ) {
  1214.       k =0;
  1215.       while ( (continue_viewing == 1) && info->DocHeaders[k] != 0 ) {
  1216.     i++;
  1217.     printf("\n    record %2d, ", i);
  1218.     dsply_doc_hdr_record( info->DocHeaders[k++]);
  1219. #ifdef FOR_DUM_TERM
  1220.     if ( i < response->NumberOfRecordsReturned ) {
  1221.       printf("\n\n  ... more to come,  enter 1 to continue or 0 to stop: ");
  1222.       scanf("%ld", &continue_viewing);
  1223.     }
  1224. #endif
  1225.       }
  1226.     }
  1227.  
  1228.     if ( info->ShortHeaders != 0 ) {
  1229.       k =0;
  1230.       while ( (continue_viewing == 1) && info->ShortHeaders[k] != 0 ) {
  1231.     i++;
  1232.     printf("\n    record %2d, ", i);
  1233.     dsply_short_hdr_record( info->ShortHeaders[k++]);
  1234. #ifdef FOR_DUM_TERM
  1235.     if ( i < response->NumberOfRecordsReturned ) {
  1236.       printf("\n\n  ... more to come,  enter 1 to continue or 0 to stop: ");
  1237.       scanf("%ld", &continue_viewing);
  1238.     }
  1239. #endif
  1240.       }
  1241.     }
  1242.  
  1243.     if ( info->LongHeaders != 0 ) {
  1244.       k =0;
  1245.       while ( (continue_viewing == 1) && (info->LongHeaders[k] != 0) ) {
  1246.     i++;
  1247.     printf("\n    record %2d, ", i);
  1248.     dsply_long_hdr_record( info->LongHeaders[k++]);
  1249. #ifdef FOR_DUM_TERM
  1250.     if ( i < response->NumberOfRecordsReturned ) {
  1251.       printf("\n\n  ... more to come,  enter 1 to continue or 0 to stop: ");
  1252.       scanf("%ld", &continue_viewing);
  1253.     }
  1254. #endif
  1255.       }
  1256.     }
  1257.  
  1258.     if ( info->Text != 0 ) {
  1259.       k =0;
  1260.       while ( (continue_viewing == 1) && (info->Text[k] != 0) ) {
  1261.     i++;
  1262.     printf("\n    record %2d, ", i);
  1263.     dsply_text_record( info->Text[k++]);
  1264. #ifdef FOR_DUM_TERM
  1265.     if ( i < response->NumberOfRecordsReturned ) {
  1266.       printf("\n\n  ... more to come,  enter 1 to continue or 0 to stop: ");
  1267.       scanf("%ld", &continue_viewing);
  1268.     }
  1269. #endif
  1270.       }
  1271.     }
  1272.  
  1273.     if ( info->Headlines != 0 ) {
  1274.       k =0;
  1275.       while ( (continue_viewing ==1) && (info->Headlines[k] != 0) ) {
  1276.     i++;
  1277.     printf("\n    record %2d, ", i);
  1278.     dsply_headline_record( info->Headlines[k++]);
  1279. #ifdef DUM_TERM
  1280.     if ( i < response->NumberOfRecordsReturned ) {
  1281.       printf("\n\n  ... more to come,  enter 1 to continue or 0 to stop: ");
  1282.       scanf("%ld", &continue_viewing);
  1283.     }
  1284. #endif
  1285.       }
  1286.     }
  1287.          
  1288.     if ( info->Codes != 0 ) {
  1289.       k =0;
  1290.       while ( (continue_viewing ==1) && (info->Codes[k] != 0) ) {
  1291.     i++;
  1292.     printf("\n    record %2d, ", i);
  1293.     dsply_code_record( info->Codes[k++]);
  1294. #ifdef FOR_DUM_TERM
  1295.     if ( i < response->NumberOfRecordsReturned ) {
  1296.       printf("\n\n  ... more to come,  enter 1 to continue or 0 to stop: ");
  1297.       scanf("%ld", &continue_viewing);
  1298.     }
  1299. #endif
  1300.       }
  1301.     }
  1302.  
  1303.     freeWAISSearchResponse(info);         
  1304.  
  1305.   }                /* display user info */
  1306.  
  1307.  
  1308.   freeSearchResponseAPDU( response);
  1309.  
  1310. }                /* twais_dsply_srch_rsp_apdu */
  1311.  
  1312.  
  1313. /*
  1314.  * 'dsply_doc_hdr_record'
  1315.  *   display one WAIS document header record 
  1316.  */
  1317. dsply_doc_hdr_record( record)
  1318. WAISDocumentHeader  *record;
  1319. {
  1320.   printf(" DocHeaders\n");
  1321.   print_any("     DocumentID:  ", record->DocumentID);
  1322.  
  1323.   printf("     VersionNumber:  %ld\n", record->VersionNumber);
  1324.  
  1325.   printf("     Score:  %ld,  BestMatch:  %ld\n", 
  1326.      record->Score, record->BestMatch);
  1327.  
  1328.   printf("     DocumentLength:  %ld,  Lines:  %ld\n", 
  1329.      record->DocumentLength,
  1330.      record->Lines);
  1331.  
  1332.   if ( record->Source )
  1333.     printf("     Source:  %s\n", record->Source);
  1334.   if ( record->Date  )
  1335.     printf("     Date:  %s\n", record->Date);
  1336.  
  1337.   if ( record->OriginCity )
  1338.     printf("     OriginCity:  %s\n", record->OriginCity);
  1339.  
  1340.   if ( record->Headline )
  1341. #ifdef FOR_DUM_TERM
  1342.     print_hdline(record->Headline);
  1343. #else
  1344.   printf("     Headline:  %s\n", record->Headline);
  1345. #endif
  1346. }
  1347.  
  1348. /*
  1349.  * 'dsply_short_hdr_record'
  1350.  *   display one WAIS short header record 
  1351.  */
  1352. dsply_short_hdr_record( record)
  1353. WAISDocumentShortHeader  *record;
  1354. {
  1355.   printf(" ShortHeaders\n");
  1356.   print_any("     DocumentID:  ", record->DocumentID);
  1357.  
  1358.   printf("     VersionNumber:  %ld\n", record->VersionNumber);
  1359.   printf("     Score:  %ld,  BestMatch:  %ld\n", 
  1360.      record->Score, record->BestMatch);
  1361.   printf("     DocumentLength:  %ld,  Lines:  %ld\n", 
  1362.      record->DocumentLength,  record->Lines);
  1363. }
  1364.  
  1365. static void print_docs _AP((DocObj** docs));
  1366.  
  1367. static void print_docs( docs)
  1368. DocObj **docs;
  1369. {
  1370.   long i;
  1371.  
  1372.   for ( i=0; docs[i] !=0; i++ ) {
  1373.     printf("    Document %ld:\n", i+1 );
  1374.     print_any("     DocID: ", docs[i]->DocumentID);
  1375.     if (docs[i]->Type != NULL)
  1376.       printf("     Type: %s\n",docs[i]->Type);
  1377.     printf("     ChunkCode: %ld\n", docs[i]->ChunkCode);
  1378.     switch ( docs[i]->ChunkCode ) {
  1379.     case CT_byte:
  1380.     case CT_line:
  1381.       printf("     Range: (%ld, %ld)\n", docs[i]->ChunkStart.Pos,
  1382.          docs[i]->ChunkEnd.Pos);
  1383.       break;
  1384.     case CT_paragraph:
  1385.       print_any("     Chunk Start: ", docs[i]->ChunkStart.ID);
  1386.       print_any("     Chunk End:   ", docs[i]->ChunkEnd.ID);
  1387.       break;
  1388.     case CT_document:
  1389.     default:
  1390.       break;
  1391.     }
  1392.   }
  1393.  
  1394. }                /* print_docs */
  1395.  
  1396.  
  1397. /*
  1398.  * "twais_dsply_srch_apdu"
  1399.  *   display search apdu on stdout
  1400.  *   the  apdu is in the specified buffer
  1401.  */
  1402. void
  1403. twais_dsply_srch_apdu( buffer)
  1404. char *buffer;           /* (I) buffer contain the search apdu */
  1405. {
  1406.   SearchAPDU  *search;
  1407.   WAISSearch  *info;
  1408.   DocObj **docs;
  1409.   any *text_search;
  1410.   long i;
  1411.  
  1412.   printf("\n\n Search Request:\n");
  1413.  
  1414.   readSearchAPDU(&search,buffer);
  1415.  
  1416.   printf("    SmallSetUpperBound:      %ld\n", search->SmallSetUpperBound); 
  1417.   printf("    LargeSetLowerBound:      %ld\n", search->LargeSetLowerBound); 
  1418.   printf("    MediumSetPresentNumber:  %ld\n", search->MediumSetPresentNumber); 
  1419.   printf("    ReplaceIndicator:        %ld\n", search->ReplaceIndicator); 
  1420.   if ( search->ResultSetName != 0 )
  1421.     printf("    ResultSetName:           %s\n", search->ResultSetName); 
  1422.   if ( search->QueryType != 0 )
  1423.     printf("    QueryType:               %s\n", search->QueryType); 
  1424.   if ( search->DatabaseNames != 0 )
  1425.     for ( i=0; search->DatabaseNames[i] != 0 ; i++ )
  1426.       printf("    Databasenames[%ld]:          %s\n", i,
  1427.          search->DatabaseNames[i]);
  1428.  
  1429.   if ( search->ElementSetNames != 0 )
  1430.     for ( i=0; search->ElementSetNames[i] != 0 ; i++ )
  1431.       printf("    ElementSetNames[%ld]:        %s\n", i,
  1432.          search->ElementSetNames[i]);
  1433.   
  1434.  
  1435.   if ( search->ReferenceID != 0 )
  1436.     print_any("    ReferenceID:             ", search->ReferenceID);
  1437.  
  1438.   if ( search->Query != 0 ) {
  1439.  
  1440.     /* type 1 */
  1441.     if ( ! strcmp( search->QueryType, QT_TextRetrievalQuery) ) {
  1442.       text_search = (any *) search->Query;
  1443.       docs = readWAISTextQuery(text_search);
  1444.       if ( docs != 0 )
  1445.     print_docs( docs);
  1446.       freeAny(text_search);
  1447.       doList((void**)docs,freeDocObj);
  1448.       s_free(docs);
  1449.     }
  1450.  
  1451.     else if ( ! strcmp( search->QueryType, QT_RelevanceFeedbackQuery) ) {
  1452.  
  1453.       info = (WAISSearch *)search->Query;
  1454.       if ( info->SeedWords != 0 )
  1455.     printf("    SeedWords:               %s\n", info->SeedWords); 
  1456.       if ( info->Docs != 0 )
  1457.     print_docs( info->Docs);
  1458.       printf("    DateFactor: %ld\n", info->DateFactor);
  1459.       if ( info->BeginDateRange )
  1460.     printf("    BeginDateRange: %s\n", info->BeginDateRange);
  1461.       if ( info->EndDateRange )
  1462.     printf("    EndDateRange:   %s\n", info->EndDateRange);
  1463.       printf("    MaxDocumentsRetrieved: %ld\n", info->MaxDocumentsRetrieved);
  1464.  
  1465.       freeWAISSearch(info);         
  1466.     }
  1467.     else {
  1468.       printf(" Unrecognized query type\n");
  1469.     }
  1470.   }
  1471.  
  1472.   freeSearchAPDU( search);
  1473.  
  1474. }                /* twais_dsply_srch_apdu */
  1475.  
  1476.  
  1477. void twais_free_apdu(apdu_buff)
  1478. char *apdu_buff;        /* (I) buffer contain the apdu */
  1479. {
  1480.   pdu_type pdu;
  1481.  
  1482.   pdu = peekPDUType(apdu_buff);
  1483.   switch ( pdu) {
  1484.   case (initAPDU):
  1485.     freeInitAPDU((struct InitAPDU *)apdu_buff);
  1486.     break;
  1487.   case (initResponseAPDU):
  1488.     freeInitResponseAPDU((struct InitResponseAPDU *)apdu_buff);
  1489.     break;
  1490.   case (searchAPDU):
  1491.     freeSearchAPDU((struct SearchAPDU *)apdu_buff);
  1492.     break;
  1493.   case (searchResponseAPDU):
  1494.     freeSearchResponseAPDU((struct SearchResponseAPDU *)apdu_buff);
  1495.     break;
  1496.   default:
  1497.     break;
  1498.   }
  1499.   
  1500. }                /* twais_free_apdu */
  1501.  
  1502.  
  1503. /*----------------------------------------------------------------------------*
  1504.  *  template apdus for testing purpose                                        *
  1505.  *----------------------------------------------------------------------------*/
  1506. void
  1507. twais_tmplt_init_apdu(buff, buff_len)
  1508. char *buff;             /* (O) buffer to hold the apdu */
  1509. long *buff_len;          /* (O) number of bytes written to the buffer */
  1510. {
  1511.   InitAPDU *init;
  1512.   char  *end_ptr;
  1513.   long len;
  1514.   any refID;
  1515.   refID.size = 2;
  1516.   refID.bytes = "10";
  1517.  
  1518.  
  1519.   init = makeInitAPDU(WILL_USE,WILL_NOT_USE,WILL_NOT_USE,WILL_NOT_SUPPORT,
  1520.               WILL_NOT_SUPPORT,
  1521.               2048L,
  1522.               2048L, NULL,
  1523.               defaultImplementationID(),defaultImplementationName(),
  1524.               defaultImplementationVersion(), &refID,NULL);
  1525.   { long buffer_len = MAX_BUFFER_LENGTH;
  1526.     end_ptr = writeInitAPDU(init,buff, &buffer_len);
  1527.   }
  1528.   len = (long)end_ptr - (long)&buff[0];
  1529.   *buff_len = len;
  1530.   freeInitAPDU(init);
  1531. }                /* twais_tmplt_init_apdu */
  1532.  
  1533.  
  1534. void
  1535. twais_tmplt_init_rsp_apdu(buff, buff_len)
  1536. char *buff;             /* (O) buffer to hold the apdu */
  1537. long *buff_len;          /* (O) number of bytes written to the buffer */
  1538. {
  1539.   WAISInitResponse *info;
  1540.   InitResponseAPDU *response;
  1541.   char  *end_ptr;
  1542.   long len;
  1543.   any refID;
  1544.   char chunk_marker[3];
  1545.   char highl_marker[2];
  1546.   char dhighl_marker[2];
  1547.   char new_line_chars[2];
  1548.   refID.size = 1;
  1549.   refID.bytes = "0";
  1550.   chunk_marker[0] = ESC;
  1551.   chunk_marker[1] = '1';
  1552.   chunk_marker[2]= 0;
  1553.   highl_marker[0] = DC1;
  1554.   highl_marker[1] = 0;
  1555.   dhighl_marker[0] = DC3;
  1556.   dhighl_marker[1] = 0;
  1557.   new_line_chars[0] = CARRIAGE_RETURN;
  1558.   new_line_chars[1] = 0;
  1559.  
  1560.   info =  makeWAISInitResponse(  CT_paragraph /* chunkCode */
  1561.                    ,3 /* chunkIDLen */
  1562.                    ,chunk_marker /* chunkMarker */
  1563.                    ,highl_marker /* highlightMarker */
  1564.                    ,dhighl_marker /* deHighlightMarker */
  1565.                    ,new_line_chars /* newLineChars */
  1566.                    );
  1567.  
  1568.   response = makeInitResponseAPDU( ACCEPT, /* result */
  1569.                   WILL_USE,WILL_NOT_USE,WILL_NOT_USE, /* search, rsp, del */
  1570.                   WILL_NOT_SUPPORT,WILL_NOT_SUPPORT, /* acc ctl, rsc ctl */
  1571.                   1024L, 2048L, /* preferred msg size, max msg size */
  1572.                   NULL,    /* authentication */
  1573.                   defaultImplementationID(),
  1574.                   defaultImplementationName(),
  1575.                   defaultImplementationVersion(),
  1576.                   &refID, /* reference id */
  1577.                   info);
  1578.   { long buffer_len = MAX_BUFFER_LENGTH;
  1579.     end_ptr = writeInitResponseAPDU(response, buff, &buffer_len);
  1580.   }
  1581.   len = (long)end_ptr - (long)&buff[0];
  1582.   *buff_len = len;
  1583.  
  1584.   CSTFreeWAISInitResponse( info);
  1585.   freeInitResponseAPDU(response);
  1586. }                /* twais_tmplt_init_rsp_apdu */
  1587.  
  1588.  
  1589.  
  1590. void twais_tmplt_typ1_srch_apdu( buff, buff_len)
  1591. char *buff;             /* (O) buffer to hold the apdu */
  1592. long *buff_len;          /* (O) number of bytes written to the buffer */
  1593. {
  1594.  
  1595.   SearchAPDU *search1;
  1596.   char  *end_ptr;
  1597.   long len;
  1598.  
  1599.   static char *database_names[2];
  1600.   any docID;
  1601.   any refID;
  1602.  
  1603.   DocObj *DocObjs[2];
  1604.   any *query;            /* changed from char* by brewster */
  1605.   database_names[0] = "Quest";
  1606.   database_names[1] = NULL;
  1607.   docID.size = 12;
  1608.   docID.bytes = "0000106776WJ";
  1609.   refID.size = 1;
  1610.   refID.bytes = "3";
  1611.    
  1612.   DocObjs[0] = makeDocObjUsingWholeDocument( &docID,NULL);
  1613.   DocObjs[1] = NULL;
  1614.  
  1615.   query = makeWAISTextQuery(DocObjs);   
  1616.  
  1617.   search1 = makeSearchAPDU( 10L, 16L, 15L, 
  1618.                1L,    /* replace indicator */
  1619.                "FOO", /* result set name */
  1620.                database_names, /* database name */   
  1621.                QT_TextRetrievalQuery, /* query_type */
  1622.                0L,    /* element name */
  1623.                &refID, /* reference ID */
  1624.                query);
  1625.  
  1626.   {
  1627.     long buffer_len = MAX_BUFFER_LENGTH;
  1628.     end_ptr = writeSearchAPDU(  search1, buff, &buffer_len);
  1629.   }
  1630.   len = (long)end_ptr - (long)&buff[0];
  1631.   *buff_len = len;
  1632.  
  1633.   CSTFreeWAISTextQuery( query);
  1634.   freeSearchAPDU(search1);
  1635.  
  1636. }                /* twais_tmplt_typ1_srch_apdu */
  1637.  
  1638. #if 0
  1639.  
  1640. twais_tmplt_typ3_srch_apdu( buff, buff_len)
  1641. char *buff;             /* (O) buffer to hold the apdu */
  1642. long *buff_len;          /* (O) number of bytes written to the buffer */
  1643. {
  1644.  
  1645.   SearchAPDU *search3;
  1646.   char  *end_ptr;
  1647.   static char *database_names[2];
  1648.   long len;
  1649.   any refID;
  1650.   WAISSearch *query;
  1651.   database_names[0] = "Quest"
  1652.     database_names[1] = NULL;
  1653.   refID.size = 1;
  1654.   refID.bytes = "3";
  1655.  
  1656.   query = makeWAISSearch( "Supercomputers in Taiwan", /* seed_words*/
  1657.              0L,    /* DocObjsPtr */
  1658.              0L,
  1659.              1L,    /* DateFactor */
  1660.              0L,    /* BeginDateRange */
  1661.              0L,    /* EndDateRange */
  1662.              10L    /* maxDocsRetrieved */
  1663.              );
  1664.  
  1665.   search3 = makeSearchAPDU( 10L, 16L, 15L, 
  1666.                1L,    /* replace indicator */
  1667.                "FOO", /* result set name */
  1668.                database_names, /* database name */   
  1669.                QT_RelevanceFeedbackQuery, /* query_type */
  1670.                0L,    /* element name */
  1671.                &refID, /* reference ID */
  1672.                query);
  1673.   {
  1674.     long buffer_len = MAX_BUFFER_LENGTH;
  1675.     end_ptr = writeSearchAPDU(  search3, buff, &buffer_len);
  1676.   }
  1677.   len = (long)end_ptr - (long)&buff[0];
  1678.   *buff_len = len;
  1679.  
  1680.   CSTFreeWAISSearch( query);
  1681.   freeSearchAPDU(search3);
  1682.  
  1683. }                /* twais_tmplt_typ3_srch_apdu */
  1684. #endif
  1685.  
  1686.  
  1687. void twais_tmplt_typ3_srch_rsp_apdu( buff, buff_len)
  1688. char *buff;
  1689. long *buff_len;
  1690. {
  1691.  
  1692.   char  *end_ptr;
  1693.   long len;
  1694.   any refID;
  1695.  
  1696.   WAISDocumentHeader  *doc_headers[3];
  1697.   WAISSearchResponse *records;
  1698.   SearchResponseAPDU *response;
  1699.   any doc_id1;
  1700.   any doc_id2;
  1701.   refID.size = 1;
  1702.   refID.bytes = "1";
  1703.   doc_id1.size = 12;   
  1704.   doc_id1.bytes = "0000106776WJ";
  1705.   doc_id2.size = 12;
  1706.   doc_id2.bytes = "0000026870WP";
  1707.  
  1708.   doc_headers[0] = makeWAISDocumentHeader(
  1709.                       &doc_id1, /* docID */
  1710.                       1L, /* versionNumber */
  1711.                       80L, /* score */
  1712.                       1L, /* bestMatch */
  1713.                       850L, /* docLen */
  1714.                       200L, /* lines */
  1715.                       NULL,    /* types */
  1716.                       "Source1", /* source */
  1717.                       "19900115", /* date */
  1718.                       "CRAY sells supercomputer to Taiwan",    /* headline */
  1719.                       "New York"); /* originCity */
  1720.  
  1721.  
  1722.   doc_headers[1] = makeWAISDocumentHeader(
  1723.                       &doc_id2, /* docID */
  1724.                       1L, /* versionNumber */
  1725.                       60L, /* score */
  1726.                       1L, /* bestMatch */
  1727.                       550L, /* docLen */
  1728.                       100L, /* lines */
  1729.                       NULL,
  1730.                       "Test Source", /* source */
  1731.                       "19900110", /* date */
  1732.                       "Test Headline", /* headline */
  1733.                       "Test City");    /* originCity */
  1734.  
  1735.   doc_headers[2] = 0;
  1736.  
  1737.   records = makeWAISSearchResponse( "Supercomputer Taiwan" /* seedWordsUsed*/
  1738.                    ,doc_headers    /* docHeaders */
  1739.                    ,0 ,0 ,0 ,0 /* shortHeaders, longHeaders, text, headlines */
  1740.                    ,0 /* codes */
  1741.                    ,NULL /* diagnostics.  KLUDGE */
  1742.                    );
  1743.  
  1744.  
  1745.   response = makeSearchResponseAPDU( SUCCESS /* result */
  1746.                     ,2 /* count */
  1747.                     ,2 /* recordsReturned */
  1748.                     ,0 /* nextPos */
  1749.                     ,0 /* ignore resultStatus since result SUCCESS */
  1750.                     ,SUCCESS /* presentStatus */
  1751.                     ,&refID /* refID */
  1752.                     ,records);
  1753.  
  1754.  
  1755.   {
  1756.     long buffer_len = MAX_BUFFER_LENGTH;
  1757.     end_ptr = writeSearchResponseAPDU(  response, buff, &buffer_len);
  1758.   }
  1759.   len = (long)end_ptr - (long)&buff[0];
  1760.   *buff_len = len;
  1761.  
  1762.   CSTFreeWAISDocumentHeader( doc_headers[0]);
  1763.  
  1764.   CSTFreeWAISDocumentHeader( doc_headers[1]);
  1765.  
  1766.   CSTFreeWAISSearchResponse( records);
  1767.   freeSearchResponseAPDU(response);
  1768.  
  1769.  
  1770. }                /* twais_tmplt_typ3_srch_rsp_apdu */
  1771.  
  1772.  
  1773. twais_tmplt_typ1_stry_rsp_apdu( buff, buff_len)
  1774. char *buff;
  1775. long *buff_len;
  1776. {
  1777.  
  1778.   char  *end_ptr;
  1779.   long len;
  1780.   any refID;
  1781.  
  1782.   WAISDocumentText *doc_text[2];
  1783.   WAISSearchResponse *records;
  1784.   SearchResponseAPDU *response;
  1785.   any docID;
  1786.   any story;
  1787.   char *story_buff;
  1788.   
  1789.   FILE *fptr;
  1790.   refID.size = 1;
  1791.   refID.bytes = "1";
  1792.   docID.size = 12;
  1793.   docID.bytes = "0000106776WJ";
  1794.   doc_text[0] = 0;
  1795.   doc_text[1] = 0;
  1796.  
  1797.   fptr = s_fopen("twais_template.txt", "r");
  1798.   if (fptr == NULL ) {
  1799.     printf(" unable to open story text file \n");
  1800.     return;
  1801.   }
  1802.    
  1803.   /* read story length */
  1804.   fread((char*)&story.size, sizeof(long), 1, fptr);
  1805.   story_buff = s_malloc( story.size +1);
  1806.   if ( story_buff == NULL) {
  1807.     printf(" insufficient memory\n");
  1808.     s_fclose( fptr);
  1809.     return;
  1810.   }
  1811.  
  1812.   /* read story text */
  1813.   fread( story_buff, 1, story.size, fptr);   
  1814.   story.bytes = story_buff;
  1815.    
  1816.   doc_text[0] = makeWAISDocumentText( &docID, 1L, &story);
  1817.  
  1818.   records = makeWAISSearchResponse( 0 /* seedWordsUsed*/
  1819.                    ,0 ,0 ,0 /* docHeaders, shortHeaders, longHeaders */
  1820.                    ,doc_text ,0    /* text, headlines */
  1821.                    ,0 /* codes */
  1822.                    ,NULL /* diagnostics.  KLUDGE */
  1823.                    );
  1824.  
  1825.  
  1826.   response = makeSearchResponseAPDU( SUCCESS /* result */
  1827.                     ,1 /* count */
  1828.                     ,1 /* recordsReturned */
  1829.                     ,0 /* nextPos */
  1830.                     ,0 /* ignore resultStatus since result SUCCESS */
  1831.                     ,SUCCESS /* presentStatus */
  1832.                     ,&refID /* refID */
  1833.                     ,records);
  1834.  
  1835.  
  1836.   {
  1837.     long buffer_len = MAX_BUFFER_LENGTH;
  1838.     end_ptr = writeSearchResponseAPDU(  response, buff, &buffer_len);
  1839.   }
  1840.   len = (long)end_ptr - (long)&buff[0];
  1841.   *buff_len = len;
  1842.  
  1843.   CSTFreeWAISDocumentText( doc_text[0]);
  1844.  
  1845.   CSTFreeWAISSearchResponse( records);
  1846.  
  1847.   freeSearchResponseAPDU(response);
  1848.  
  1849.   s_free(story_buff);
  1850.   s_fclose(fptr);
  1851.  
  1852. }                /* twais_tmplt_typ1_stry_rsp_apdu */
  1853.  
  1854.  
  1855. twais_tmplt_typ3_srch_apdu( buff, buff_len)
  1856. char *buff;             /* (O) buffer to hold the apdu */
  1857. long *buff_len;          /* (O) number of bytes written to the buffer */
  1858. {
  1859.  
  1860.   SearchAPDU *search3;
  1861.   char  *end_ptr;
  1862.   static char *database_names[7] = { 
  1863.     "11111111111111111111111111111111111111111111111111",
  1864.     "22222222222222222222222222222222222222222222222222",
  1865.     "33333333333333333333333333333333333333333333333333",
  1866.     "44444444444444444444444444444444444444444444444444",
  1867.     "55555555555555555555555555555555555555555555555555",
  1868.     "66666666666666666666666666666666666666666666666666",
  1869.     0};
  1870.   static char *elem_names[7] = { ES_DocumentHeader
  1871.                    ,ES_DocumentShortHeader
  1872.                      ,ES_DocumentLongHeader
  1873.                        ,ES_DocumentText
  1874.                      ,ES_DocumentHeadline
  1875.                        ,ES_DocumentCodes
  1876.                          ,0};
  1877.  
  1878.   long len;          
  1879.   any refID;
  1880.   WAISSearch *query;
  1881.   refID.size = 1;
  1882.   refID.bytes = "3";
  1883.  
  1884.   query = makeWAISSearch( 
  1885.              "What is the penalities for driving without insurance",
  1886.              0L,    /* DocObjsPtr */
  1887.              0L,
  1888.              1L,    /* DateFactor */
  1889.              0L,    /* BeginDateRange */
  1890.              0L,    /* EndDateRange */
  1891.              10L    /* maxDocsRetrieved */
  1892.              );
  1893.  
  1894.   search3 = makeSearchAPDU( 10L, 16L, 15L, 
  1895.                1L,    /* replace indicator */
  1896.                "FOO", /* result set name */
  1897.                database_names, /* database name */   
  1898.                QT_RelevanceFeedbackQuery, /* query_type */
  1899.                elem_names, /* element name */
  1900.                &refID, /* reference ID */
  1901.                query);
  1902.   {
  1903.     long buffer_len = MAX_BUFFER_LENGTH;
  1904.     end_ptr = writeSearchAPDU(  search3, buff, &buffer_len);
  1905.   }
  1906.   len = (long)end_ptr - (long)&buff[0];
  1907.   *buff_len = len;
  1908.  
  1909.   CSTFreeWAISSearch( query);
  1910.   freeSearchAPDU(search3);
  1911.  
  1912. }                /* twais_tmplt_typ3_srch_apdu */
  1913.  
  1914.